package com.brightworks.scripthelper.analyzers
{
    import com.brightworks.scripthelper.constants.LineTypeConstants;
    import com.brightworks.scripthelper.constants.MiscConstants;
    import com.brightworks.util.Log;

    public class LineTypeAnalyzer_Header_Roles extends LineTypeAnalyzer
    {
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
        //
        //          Getters & Setters
        //
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

        public static function get lineTypeDescription():String
        {
            return LineTypeConstants.LINE_TYPE_DESCRIPTION__HEADER__ROLES;
        }

        public static function get lineTypeId():String
        {
            return LineTypeConstants.LINE_TYPE_ID__HEADER__ROLES;
        }

        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
        //
        //          Public Methods
        //
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

        public function LineTypeAnalyzer_Header_Roles()
        {
            super();
        }

        override public function getProblemReports():Array
        {
            var problemList:Array = [];
            var isLineBeginningCorrect:Boolean = false;
            if ((lineText.indexOf("Roles: ") == 0) || (lineText == "Roles:"))
            {
                isLineBeginningCorrect = true;
            }
            if (!isLineBeginningCorrect)
            {
                problemList.push("Based on its position as the 10th line in the script, this line should be the " + LineTypeConstants.LINE_TYPE_DESCRIPTION__HEADER__ROLES + ". It should start with 'Roles:', and if roles are specified, there should be a space after the colon.");
            }
            else
            {
                var rolesList:Array = getRolesList();
                switch (rolesList.length)
                {
                    case 0:
                        problemList.push("Based on its position as the 9th line in the script, this line should be the " + LineTypeConstants.LINE_TYPE_DESCRIPTION__HEADER__ROLES + ", and should specify '" + MiscConstants.ROLE_DEFAULT + "' or a list of role names, separated by colons, with no spaces before or after the colons. This line does not do either of these things.");
                        break;
                    case 1:
                        // If we have one role, any name is acceptable
                        break;
                    default:
                        if (problemList.indexOf(MiscConstants.ROLE_DEFAULT) != -1)
                        {
                            problemList.push("In a " + LineTypeConstants.LINE_TYPE_DESCRIPTION__HEADER__ROLES + ", if the '" + MiscConstants.ROLE_DEFAULT + "' role is specified, it should be the only role. In this line, '" + MiscConstants.ROLE_DEFAULT + "' is one of several roles");
                        }
                }
            }
            return constructFullProblemStrings(problemList);
        }

        public function getRolesList():Array
        {
            if (lineText.indexOf("Roles: ") != 0)
                return [];
            var listString:String = lineText.substring(7, lineText.length);
            if (listString.indexOf(" :") != -1)
                return [];
            if (listString.indexOf(": ") != -1)
                return [];
            var listArray:Array = listString.split(":");
            return listArray;
        }

        public static function isLineThisType(lineString:String, lineStringList:Array=null, lineNum:int=-1):Boolean
        {
            // We use another, external, method to determine this at this point, so this method isn't used.
            Log.fatal("LineTypeAnalyzer_Header_Roles.isLineThisType(): Method not implemented");
            return false;
        }

        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
        //
        //          Private Methods
        //
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

    }
}
